<?php
/**
 * @package Joomla
 * @subpackage Jmonoslideshow
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jmonoslideshow is a Joomla extension for Monoslideshow.
 *
 * Jmonoslideshow uses :
 * Monoslideshow (http://www.monoslideshow.com/)
 * Plupload (http://www.plupload.com/) by Moxicode Systems
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * jquery a JavaScript Library (http://jquery.com/)
 * getid3 library (http://getid3.sourceforge.net/)
 * swfobject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file (http://code.google.com/p/swfobject/)
 * Chained Selects jQuery Plugin (http://www.appelsiini.net/2010/jquery-chained-selects)
 *
 * Jmonoslideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
require_once JPATH_COMPONENT_ADMINISTRATOR.DS.'library'.DS.'ThumbLib.inc.php';
$user		= JFactory::getUser();
$userId		= $user->get('id');
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));
$n			= count($this->items);

$params = &JComponentHelper::getParams( 'com_jmonoslideshow' );
$maxThumbnailWidth = $params->get('width_vignette', '120');
$maxThumbnailHeight = $params->get( 'height_vignette', '90' );
$base_upload_dir = JPATH_ROOT.DS . 'media' . DS . 'com_jmonoslideshow' . DS . 'upload' ;
$jpgQuality = $params->get( 'qualtiy_image', '75' );
$options = array('jpegQuality' => $jpgQuality);

$categoryId	= $this->state->get('filter.catid');
$categoryId	= $categoryId ? $categoryId[0] : '';


if ( !JFolder::exists($base_upload_dir.'/'.$maxThumbnailWidth.'-'.$maxThumbnailHeight) ) { JFolder::create($base_upload_dir.'/'.$maxThumbnailWidth.'-'.$maxThumbnailHeight); }

?>
<?php foreach($this->items as $i => $item):
		$ordering	= ($listOrder == 'rel.ordering');
		$canCreate	= $user->authorise('core.create',		'com_dictionary.category.'.$item->id);
		$canEdit	= $user->authorise('core.edit',			'com_dictionary.category.'.$item->id);
		$canCheckin	= $user->authorise('core.manage',		'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
		$canChange	= $user->authorise('core.edit.state',	'com_dictionary.category.'.$item->id) && $canCheckin;
?>
<tr class="row<?php echo $i % 2; ?>" id="listItem_<?php echo $item->media_category_id; ?>">
  <td><?php echo $this->pagination->getRowOffset( $i ); ?></td>
  <td><?php echo JHtml::_('grid.id', $i, $item->id); ?></td>
  <td>
    <?php if ($item->checked_out){ ?>
    <?php echo MediaHelper::getThumb($item->filename, $item->thumbname, $item->id )  ?>
    <?php
				} else {
				?>
    <a href="<?php echo JRoute::_('index.php?option=com_jmonoslideshow&task=media.edit&id='.$item->id); ?>">  <?php echo MediaHelper::getThumb($item->filename, $item->thumbname, $item->id )  ?></a>
    <?php
				} ?></td>
  <td><?php if ($item->checked_out){
					echo $this->escape($item->title);
				} else {
				?>
    <a href="<?php echo JRoute::_('index.php?option=com_jmonoslideshow&task=media.edit&id='.$item->id); ?>"> <?php echo $this->escape($item->title); ?></a>
    <?php
				} ?></td>
  <td><?php echo JText::_( MediaHelper::getTypeName($this->escape($item->type))); ?></td>
  <td>
  <?php 
				$nr = count($item->categories);
				$ix = 0;
				foreach ($item->categories as $key => $category) :
					$catlink	= 'index.php?option=com_categories&view=category&layout=edit&id='.$category->id.'&extension=com_jmonoslideshow';
					$title = htmlspecialchars($category->title, ENT_QUOTES, 'UTF-8');
				?>
					<span>
					<a href="<?php echo $catlink; ?>">
						<?php 
						if (JString::strlen($title) > 20) {
							echo JString::substr( $title , 0 , 20).'...';
						} else {
							echo $title;
						}
						?></a></span>
					<?php 
					$ix++;
					if ($ix != $nr) :
						echo ', ';
					endif;
				endforeach;
				?>
  </td>
  <td><?php 
			$tags = $item->tags;
			
			foreach ($tags as $key => $value) 
				{
					echo '<div class="tags">'.$value.'</div> ';
				}
				
			
			
			?></td>
     
  <td <?php if ($ordering && $categoryId !=0 ) :  ?>  class="order"<?php endif; ?> align="center">
  <?php if ($ordering && $categoryId !=0 ) :  ?> <img src="<?php echo JURI::root(); ?>media/com_jmonoslideshow/images/admin/move.png" /><?php else: ?> <?php echo $item->ordering; ?> <?php endif; ?>
    </td>
	
  <td class="center"><?php echo $this->escape($item->author_name); ?></td>
  <td class="center nowrap"><?php echo JHtml::_('date',$item->created, JText::_('DATE_FORMAT_LC4')); ?></td>
  <td class="center"><?php echo JHtml::_('jgrid.published', $item->published, $i, 'medias.', true); ?></td>
  <td><?php echo $item->id; ?></td>
</tr>
<?php endforeach; ?>
